package pers.fjl.test.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import pers.fjl.common.constant.MessageConstant;
import pers.fjl.common.entity.QueryPageBean;
import pers.fjl.common.entity.Result;
import pers.fjl.common.po.User;
import pers.fjl.common.validation.ValidGroup;
import pers.fjl.test.annotation.LoginRequired;
import pers.fjl.test.service.GoodsService;
import pers.fjl.test.service.UserItemService;

import javax.annotation.Resource;

/**
 * 商品管理模块
 *
 * @author fangjiale 2021年1月1日
 */

@Api(value = "商品模块", description = "商品模块的接口信息")
@RequestMapping("/goods")
@RestController
@CrossOrigin
@Slf4j
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    //    @IpRequired
    @LoginRequired
    @ApiOperation(value = "分页查询", notes = "返回分页数据")
    @PostMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        return new Result(true, MessageConstant.OK, "获取分页数据成功", goodsService.findPage(queryPageBean));
    }

    @ApiOperation(value = "商品状态更新", notes = "更新商品的禁用状态")
    @PutMapping("/{cid}/state/{onSale}")
    public Result userStateChanged(@PathVariable("cid") Integer cid,
                                   @PathVariable("onSale") boolean onSale) {
        boolean flag = goodsService.goodsStateChanged(cid, onSale);
        return new Result(flag, MessageConstant.OK);
    }
}
